using System;
using System.Collections;
using System.Collections.Generic;
using MyFrame.Single;
using UnityEngine;

[Serializable]
public enum GameState
{
    Starting,
    Playing,
    Paused,
    GameOver
}

public class GameMgr : SingletonMonoGlobal<GameMgr>
{
    public Player player;
    public PlayerInputActions UIInputActions;

    public GameState CurrentState { get; private set; }

    void Awake()
    {
        Time.timeScale = 1f; // 确保游戏正常运行
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();

        UIInputActions = new PlayerInputActions();
        UIInputActions.Enable();
    }

    void Start()
    {
        ChangeState(GameState.Starting);
    }
    private void OnDestroy() {
    }

    public static event Action<GameState> OnBeforeGameStateChanged;
    public static event Action<GameState> OnAfterGameStateChanged;

    public void ChangeState(GameState state)
    {
        OnBeforeGameStateChanged?.Invoke(state);
        CurrentState = state;
        switch (state)
        {
            case GameState.Starting:
                HandleStarting();
                break;
            case GameState.Playing:
                break;
            case GameState.Paused:
                break;
            case GameState.GameOver:
                break;
            default:
                throw new ArgumentOutOfRangeException(nameof(state), state, null);
        }

        OnAfterGameStateChanged?.Invoke(state);
    }

    private void HandleStarting()
    {
        ChangeState(GameState.Playing);
    }
}
